-
-
Notifications
You must be signed in to change notification settings - Fork 45
URL Rewriting #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL Rewriting #872
Conversation
Thank you, @marmoure and @adamretter. With the stated goal of #200 being a thoroughly updated article that is approachable and presents the key information that users need to know about the URL Rewriting facility (a "major job", as Erik characterized it), I'd suggest that more revision is necessary here. Wolfgang's draft revised introduction is a good start, but the body of the article needs to be reviewed to meet the stated goals of #200. As a starting point, I would suggest reading the relevant sections from the eXist book (pp. 194-207), since it comprehensively describes the URL rewriting facility. Make a note of what's covered there - for example, permissions considerations - and be sure all information is addressed here and introduced coherently. As Erik recommended, "postpone stuff about servlets and MVC patterns and all stuff you don't need for the basic understanding to sections at the end." The article should address the typical user looking to exert full control over their URLs and tell them what they need to know to do so. Also, please be sure the CI passes. |
@joewiz I've spent some time reworking the article, restructuring in some places, adding examples, and aiming for a more concise wording. How does it look? |
@yamahito much clearer now 👍🏼 |
<?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" schematypens="http://relaxng.org/ns/structure/1.0"?><?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?><article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"> | ||
<info> | ||
<title>URL Rewriting</title> | ||
<date>2Q19</date> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Author Reference, this should be updated to February 2023 or 1Q23.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes; will fix that.
</orderedlist> | ||
<sect2 xml:id="eg1"> | ||
<title>Example I: A Simple Implementation</title> | ||
<para>Consider the document you are currently reading; a direct URL pointing to the source data might be <code>/exist/apps/doc/data/urlrewrite.xml</code>. But accessing this URI would only show a user the raw XML: instead users should get a properly formatted HTML version of the text, accessible through a simple URL like <code>/exist/apps/doc/urlrewrite</code>.</para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the direct source URL to the source XML for this article would be /exist/rest/db/apps/doc/data/urlrewrite.xml
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will reword this, since the URLs do not really point to this exact document (which is at /exist/apps/doc/data/urlrewrite/urlrewrite.xml
- I think bringing the rest interface into it muddies the waters even further). I considered changing all of the URLs to match the actual docbook article, but I think the important thing is that they are consistent.
</term> | ||
</orderedlist> | ||
<sect2 xml:id="eg1"> | ||
<title>Example I: A Simple Implementation</title> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next example is "Example 2", so perhaps best to stick with Arabic numerals -> "Example 1".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added Example C fixed.
declare variable $exist:root external; | ||
|
||
<dispatch xmlns="http://exist.sourceforge.net/NS/exist"> | ||
<forward url="{$exist:controller}/modules/transform.xql"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text refers to this XQuery as transform.xq
- i.e., without the l
.
<dispatch xmlns="http://exist.sourceforge.net/NS/exist"> | ||
<forward url="data/{$exist:resource}.xml"/> | ||
<view> | ||
<forward url="{$exist:controller}/modules/transform.xql"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text refers to this XQuery as transform.xq
- i.e., without the l
.
<para><literal>controller.xq</literal> is invoked for all URL paths targeting the collection in which it resides. It has access to a number of <xref linkend="variables"/> pre-filled with details about the request, including <literal>$exist:resource</literal>, containing the name of the resource (without path components) the request tries to access; also the <literal>$exist:controller</literal> variable which points to the collection the <literal>controller.xq</literal> is located in.</para> | ||
<para>For example, one may want to direct all requests to <literal>/exist/apps/doc/{resource}</literal> to an XQuery, <literal>transform.xq</literal>, which is responsible for converting the XML content into HTML:</para> | ||
<programlisting language="xquery" xlink:href="listings/listing-1.txt"/> | ||
<para>This example controller returns a simple <tag>dispatch</tag> fragment which will be passed back to the URL rewriting framework. The <tag>forward</tag> element instructs the framework to call the URL <literal>modules/transform.xq</literal> relative to the collection in which the controller resides. It adds a request parameter, named <literal>doc</literal>, which translates the requested resource into an actual document path to be transformed.</para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding another sentence to the end of this paragraph:
The receiving query could access this parameter using
request:get-parameter("doc", ())
in order to retrieve the requested article.
<para><literal>controller.xq</literal> is invoked for all URL paths targeting the collection in which it resides. It has access to a number of <xref linkend="variables"/> pre-filled with details about the request, including <literal>$exist:resource</literal>, containing the name of the resource (without path components) the request tries to access; also the <literal>$exist:controller</literal> variable which points to the collection the <literal>controller.xq</literal> is located in.</para> | ||
<para>For example, one may want to direct all requests to <literal>/exist/apps/doc/{resource}</literal> to an XQuery, <literal>transform.xq</literal>, which is responsible for converting the XML content into HTML:</para> | ||
<programlisting language="xquery" xlink:href="listings/listing-1.txt"/> | ||
<para>This example controller returns a simple <tag>dispatch</tag> fragment which will be passed back to the URL rewriting framework. The <tag>forward</tag> element instructs the framework to call the URL <literal>modules/transform.xq</literal> relative to the collection in which the controller resides. It adds a request parameter, named <literal>doc</literal>, which translates the requested resource into an actual document path to be transformed.</para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's totally accurate to say that the request parameter named doc
"translates the requested resource into an actual document path". Instead, doc
contains the name of the resource sans path components (e.g., urlrewrite
) plus the file extension of the actual document stored in the database (e.g., urlrewrite.xml
).
@joewiz I've attempted to address your feedback points. Thanks! |
- `xref/@linkend` already correctly handles cross references using the title of the resource, but `link` can also use `@linkend` where internal links are desirable with different labels. - Refactored for best practice push XSLT paradigm.
- Built on existing work by Wolfgang and others - removed extra verbal padding for more concise document - Re-ordered some of the more complex topics to the end of the document - Re-factored headings for easier navigation from sidebar (e.g. controller XML model) and better internal linking - Reviewed the eXist O'Reilly book content to ensure documentation parity - Added some examples
- missing @xml:id on `sect2` - replace `tag` within `link` with `literal`
- corrected query names to `.xq` from `xql` in examples - Updated date - renumbered examples for consistency - Reworded Example 1
@joewiz I have fixed the date and cleaned up the commit history. This should be ready for you to merge now if you are happy to do so. |
@adamretter Would you please pull in my evolvedbinary#1, so that this PR incorporates that review? |
@joewiz Sorry, I wasn't aware of your evolvedbinary#1. I just took a look at that PR and there seems to be merge conflicts. Can I suggest that this gets merged first, and then you could reopen your PR against this repo. |
@adamretter Ok, that'll work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yamahito Thanks, this is a great article!
Closes #200 .
This PR uses @wolfgangmm #227 for the URL Rewriting and all the fixes in that Pr.
It removes outdated parts, rename all
xql
toxq
.This open source contribution to the documentation project was commissioned by the Office of the Historian, U.S. Department of State, https://history.state.gov/.